package com.fang.networkdisk.controller;

import com.fang.common.common.CommonPage;
import com.fang.common.common.CommonResult;
import com.fang.common.request.BaseController;
import com.fang.common.util.CommonResultUtil;
import com.fang.networkdisk.entity.bo.RequestPathBo;
import com.fang.networkdisk.entity.dto.RequestPathDto;
import com.fang.networkdisk.entity.vo.RequestPathVo;
import com.fang.networkdisk.service.TbNetDisRequestPathService;
import com.fang.networkdisk.util.NDBeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Bernie_fang
 * @Description:
 * @create 2025/2/3 16:24
 **/
@RestController
@RequestMapping("/system/requestPath")
public class RequestPathController extends BaseController {

    @Resource
    private TbNetDisRequestPathService tbNetDisRequestPathService;

    @PostMapping("/list")
    public CommonResult<CommonPage<List<RequestPathVo>>> queryRequestPath(@RequestBody RequestPathDto RequestPathDto) {
        RequestPathBo RequestPathBo = new RequestPathBo();
        NDBeanUtils.copyListProperties(RequestPathDto, RequestPathBo);
        CommonPage result = tbNetDisRequestPathService.queryRequestPath(RequestPathBo);
        return CommonResultUtil.success(result);
    }

    @PostMapping("/add")
    public CommonResult<CommonPage<List<RequestPathVo>>> addRequestPath(@RequestBody RequestPathDto RequestPathDto) {
        String authorId = super.getAuthorId();
        RequestPathBo requestPathBo = new RequestPathBo();
        NDBeanUtils.copyListProperties(RequestPathDto, requestPathBo);
        requestPathBo.setCreateUser(authorId);
        requestPathBo.setUpdateUser(authorId);
        tbNetDisRequestPathService.addRequestPath(requestPathBo);
        return CommonResultUtil.success();
    }

//    @PostMapping("/update")
//    public CommonResult<CommonPage<List<RequestPathVo>>> updateRequestPath(@RequestBody RequestPathDto RequestPathDto) {
//        String authorId = super.getAuthorId();
//        RequestPathBo requestPathBo = new RequestPathBo();
//        NDBeanUtils.copyListProperties(RequestPathDto, requestPathBo);
//        requestPathBo.setCreateUser(null);
//        requestPathBo.setUpdateUser(authorId);
//        tbNetDisRequestPathService.updateRequestPathById(requestPathBo);
//        return CommonResultUtil.success();
//    }

    @GetMapping("/delete/{id}")
    public CommonResult<CommonPage<List<RequestPathVo>>> deleteRequestPath(@PathVariable("id") Integer id) {
        String authorId = super.getAuthorId();
        tbNetDisRequestPathService.deleteRequestPathById(id, authorId);
        return CommonResultUtil.success();
    }


}
